Sun River
Topics about Java SE, Servlet/JSP, JDBC, MultiThread, UML, Design Pattern, CSS, JavaScript, Maven, JBoss, Tomcat, ...
posts - 78,comments - 0,trackbacks - 0
   

---Which of the following methods can be called to change the state of the CMP entity bean from pooled to the ready state?

ejbStore()  

ejbCreate()

ejbActivate()

ejbFind()  

setEntityContext()

 

--- Consider the following snippets:

public class FooBean implements SessionBean, FooRemoteBusiness {
  
// bean stuff
}

public interface FooRemoteHome extends EJBHome {
   
   FooRemote create() 
throws CreateException, RemoteException;
   
}

FooRemoteHome home
= ...;
home.create();
home.create();
home.create();

How many beans have been created?

1

3 

5 

It depends on the server vendor.

Note: Home interface create() method only requests a reference to the stateless bean. Server is responsible for pooling bean instances so we cannot state how many instances have been created due to our calls.

 

--- Which of the following are true about stateful session bean?

x

An instance of stateful session bean is created by the container when the client invokes a create method on the remote home interface.

 

An instance of stateful session bean is removed by the container when the client invokes a no-argument remove method on the remote home interface.

 

Each EJBObject of the stateful session bean has a reference to its own EJBHome.

 

An instance of stateful session bean is removed by the container when the client invokes a remove(Object o) method on the remote home interface.

 

---All enterprise JavaBeans are required to be serializable - that is why EnterpriseBean interface extends Serializable .

 

---When does the Container call ejbPassivate() on an entity bean?

 

When the container wants to remove the association between the bean and the remote object, but doesn't want the object's state removed from persistent store.

 

When the client calls a business method on the EJBObject.

 

When the bean is put to sleep and is no longer taking up space on the heap.

 

When the bean's state needs to be serialized.

Note:

explanation

By calling ejbPassivate, the bean can release any resources it allocated while in the active state, but it doesn't have to update persistent storage for the entity it represents.

 

---What is true about session beans ?

 

The session bean class may be declared final.

 

The session bean class may be declared abstract.

 

The session bean class may have a finalize() method.

x

The session bean class may implement the no-argument constructor.

 

---A home interface has the following method signature:

remove(Object key)

Which of the following is guaranteed?

 

It is a local home interface

 

It is a remote home interface

x

It is a remote or local home interface

Note: Both java.ejb.EJBHome and java.ejb.EJBLocalHome have methods with the above method signature. (Exceptions and return type are not shown since the question asks only about the method signature).

 

---Assume we have a server running a client bean A that does the following to get a reference to the server bean B (home is BHome) running in a different server.

Object bref = new InitialContext().lookup("java:comp/env/ejb/myBRef");
BHome bhome
= (BHome) PortableRemoteObject.narrow(bref, BHome.class);


In the above snippet, we are constructing a BHome instance by looking it up from JNDI. What is the pass by mechanism used under the cover to get us a BHome instance?

 

Pass by value

x

Pass by reference

 

Pass reference by value

Note: What is bound to the JNDI is the stub of the home object. What gets sent to the client is thus a stub which is actually the remote reference to the actual home.

 

--- One EJB can access an environment entry of another EJB but must obtain a reference to the environment naming context of the other EJB first.

FALSE

 

 

explanation

Environment entries are are only accessible from the EJB that specified them (EJB 2.1 spec 20.2.1.2)

 

---Which of the following lines should be inserted at line 6 to obtain a reference to the local home interface of MyBean?

01: MyBeanLocalHome home = null;
02: 
03: try {
04:    InitialContext ctx = new InitialContext();
05:    Object obj = ctx.lookup("MyBean");
06:    home = ...
07: }
08: catch (NamingException ne) {
09:    ne.printStackTrace();
10: }

 

 

home = (MyBeanLocalHome) PortableRemoteObject.narrow(obj, MyBeanLocalHome.class);

 

 

home = (MyBeanLocalHome) PortableLocalObject.narrow(obj, MyBeanLocalHome.class);

 

 

home = (MyBeanLocalHome) obj;

 

 

home = Class.newInstance(obj, MyBeanLocalHome.class);

Note: Because it is local, there is no need to narrow the Home reference. A cast is sufficient.

---If a business method in a bean class throws a java.lang.RuntimeException, what will be the type of the exception that will be received by a local client?

 

java.lang.RuntimeException

 

java.lang.Exception

 

java.rmi.RemoteException

x

javax.ejb.EJBException

 

java.ejb.RuntimeException

The container will throw a java.ejb.EJBException when an exception of type java.lang.RuntimeException (or a sub-type) is thrown by the bean.

 

---Which functionality is provided that is common to both a session bean's remote and local component interfaces? (3 correct options)

x

Obtaining the session object's home interface.

 

Obtaining the session object's primary key.

 

Obtaining the handle of the session object.

x

Removing the session object.

x

Testing if a given session object is identical to the invoked session object.

Answers 1, 4 and 5 are correct. Answer 1 is correct. A remote client can obtain a session object's home interface by calling getEJBHome() on the session object's remote component interface. A local client can obtain a session object's home interface by calling getEJBLocalHome() on the session object's local component interface. Answer 4 is correct because both remote and local clients can remove a session object by calling remove() on the session object's component interface. Answer 5 is correct. Both remote and local clients can test if their corresponding session objects are identical to another session object. A remote client can use javax.ejb.EJBObject.isIdentical(EJBObject obj) and a local client can use javax.ejb.EJBLocalObject.isIdentical(EJBLocalObject obj).

Answer 2 is incorrect. Although both remote and local components define a getPrimaryKey() method, this functionality is not applicable to session beans. This method is used to get the identity of an entity bean. Answer 3 is incorrect because this functionality is only available in the remote component interface and not in the local component interface.

--- Which of the following methods can be invoked by the container on a stateless session bean?

 

create()

 

ejbCreate(String specId)

x

ejbRemove()

 

ejbCreateSpec()

x

ejbCreate()

 

remove()

The create() and remove() methods are called by the client, and the corresponding ejbCreate() and ejbRemove() methods are called by the container.

The ejbCreate(String specId) and ejbCreateSpec() methods are possible for stateful session beans only (need corresponding create(String specId) and createSpec() in Home interface).

--- Which of the following lines should be inserted at line 6 to obtain a reference to the local home interface of MyBean?

01: MyBeanLocalHome home = null;
02: 
03: try {
04:    InitialContext ctx = new InitialContext();
05:    Object obj = ctx.lookup("MyBean");
06:    home = ...
07: }
08: catch (NamingException ne) {
09:    ne.printStackTrace();
10: }

 

home = (MyBeanLocalHome) PortableRemoteObject.narrow(obj, MyBeanLocalHome.class);

 

home = (MyBeanLocalHome) PortableLocalObject.narrow(obj, MyBeanLocalHome.class);

xx

home = (MyBeanLocalHome) obj;

 

home = Class.newInstance(obj, MyBeanLocalHome.class);

 

--- Which of the following may an Enterprise Javabean (EJB) Java archive (.jar) file may contain?

x

A. The ejb-jar.xml file

x

B. The EJB implementation class

x

C. The EJB Local or Remote interface

 

D. JSP tag library classes

 

--- Assume we have a server running a client bean A that does the following to get a reference to the server bean B (home is BHome) running in a different server.

Object bref = new InitialContext().lookup("java:comp/env/ejb/myBRef");
BHome bhome
= (BHome) PortableRemoteObject.narrow(bref, BHome.class);

In the above snippet, we are constructing a BHome instance by looking it up from JNDI. What is the pass by mechanism used under the cover to get us a BHome instance?

 

Pass by value

x

Pass by reference

 

Pass reference by value

Note: What is bound to the JNDI is the stub of the home object. What gets sent to the client is thus a stub which is actually the remote reference to the actual home.

 

--- Check all possible answers.

x

When a RemoveException is thrown from the ejbRemove() method of an entity bean where the corresponding remove() method has CMT attribute Mandatory,the client will receive this RemoveException.

x

If the Container denies a client access to a business method, the client will receive RemoteException or EJBException.

 

When a NoSuchObjectException is thrown from an ejbHome<METHOD>(...) method of an entity bean where the corresponding home method has CMT attribute RequiresNew,the client's transaction if any must be marked for rollback.

x

When a system exception is thrown from the onMessage() method of a MDB with BMT, any transaction that has been started, but not yet completed, by the instance must be marked for rollback.

For option A: RemoveException is application exception, ejbRemove() runs in the context of the caller's transaction, so container will re-throw the exception to the client, thus client can receive RemoveException.
For option B: Although ejbRemove() runs with unspecified transaction context, but client can still receive RemoveException.
For option C: NoSuchObjectException is system exception, only container-started transaction will be rollbacked, the client transaction may or may not be marked for rollback.
For option D: when system exception is generated from MDB's bean method with BMT, the container will log the exception and mark for a rollback a transaction has been started, but not yet completed, and discard the instance.

 

--- Suppose I want to create a session bean that works as a proxy to other objects, that is, since the Session Bean can be published and called remotely, this session bean could work as a bridge between clients and server classes. Which patterns would you use to implement that?

x

Session Facade, so that the EJB points to a class that implements all the behavior.

x

Service Delegate, so that a POJO class knows how to invoke remotely the session bean.

x

Command Pattern, to invoke the appropriate remote class method, translating the name of the method to the actual method.

x

Dynamic Proxy, to transparently handle the invocation as if it were a local invocation, serializing the name of the method.

 

Factory Pattern, to centralize the instantiation of the object.

 

--- Which are subclasses of java.lang.RuntimeException?

x

javax.ejb.NoSuchEntityException

 

java.rmi.NoSuchObjectException

x

javax.ejb.NoSuchObjectLocalException

x

javax.ejb.AccessLocalException

 

javax.transaction.TransactionRequiredException

 

--- You have developed an EJB that you do not want to take part in any transactions. However you do not want the caller to be informed of this behaviour. What transactional level should you choose to tell  the container you wish this behaviour?

 

NoTrans.

x

NotSupported.

 

Never.

 

Required.

 

NotRequired.

 

explanation

NotSupported is the correct answer as it will suspend the transaction of the caller until it's methods (and methods it calls) have completed. The caller will not be informed of this behaviour.
Never will throw an exception to the caller, if the caller makes a call from within a transactional context.
Required specifies the EJB must be in a transactional context so does not match the described behaviour that is required. The other option NotRequired does not exist.

 

--- Which of the following sentences best describes the method SessionSynchronization.beforeCompletion() ?

x

The beforeCompletion method notifies a session bean instance that a transaction is about to be committed.

 

The beforeCompletion method notifies an EJB container that a transaction is about to be committed.

 

The beforeCompletion method notifies a servlet container that a transaction is about to be committed.

 

The beforeCompletion method notifies a session bean manager that a transaction is about to be committed.

 

Note: The beforeCompletion method notifies a session bean instance that a transaction is about to be committed.

 

--- Which of the following characteristics of EJB QL are true?

x

EJB QL defines operators and expressions based on the Entity Beans data model and their relationships.

x

The Bean Provider uses EJB QL to write queries based on the abstract persistence schemas and the relationships defined in the deployment descriptor.

x

EJB QL depends on navigation and selection based on the cmp-fields and cmr-fields of the related entity beans.

x

The Bean Provider can navigate from an entity bean to other entity beans by using the names of cmr-fields in EJB QL queries.

 

--- What is the proportion the EJB component objects managed by the container to the amount of the beans managed by it?

 

1 to n
Container manages single EJB component object of given type no matter how many beans are instantiated. Access to the EJB component object is synchronized.

 

n to n
Container manages separated EJB component object of given type associated with each created bean. Access to the EJB component object don't have to synchronized.

 

m to n
Container manages some amount of the EJB component objects of given type, usually smaller then amount of instantiated beans. Access to the EJB component object is synchronized in such case.

x

It depends on the server vendor

All the three first scenarios are correct but server vendor is free to choose appropriate strategy.

 

--- Which of the following statements are true about Bean Managed Transaction in EJB2.0?

 

If a message driven bean instance starts a transaction in the onMessage() method, and it returns before committing the transaction, the container will throw an exception.

x

If a stateless session bean instance starts a transaction in a business method, and it returns before committing the transaction, the container will throw an exception.

 

If a stateful session bean instance starts a transaction in a business method, and it returns before committing the transaction, the container will throw an exception.

 

If an entity bean instance starts a transaction in a business method, and it returns before committing the transaction, the container will throw an exception.

 

--- When using container-managed relationships, the <cascade-delete/> element inside a <ejb-relationship-role> element is valid if

 

the <ejb-relationship-role> element has a multiplicity of One and the other side has a multiplicity of Many

x

the <ejb-relationship-role> element has a multiplicity of Many and the other side has a multiplicity of One

x

the <ejb-relationship-role> element has a multiplicity of One and the other side has a multiplicity of One

 

the <ejb-relationship-role> element has a multiplicity of Many and the other side has a multiplicity of Many

Note:

<cascade-delete/> is valid inside the <ejb-relationship-role> element only if the other side has a multiplicity of One. See EJB 2.1 spec 10.3.4.2.

 

--- Which of the following statements are true about Bean Managed Transaction in EJB2.0?

 

If a message driven bean instance starts a transaction in the onMessage() method, and it returns before committing the transaction, the container will throw an exception.

x

If a stateless session bean instance starts a transaction in a business method, and it returns before committing the transaction, the container will throw an exception.

 

If a stateful session bean instance starts a transaction in a business method, and it returns before committing the transaction, the container will throw an exception.

 

If an entity bean instance starts a transaction in a business method, and it returns before committing the transaction, the container will throw an exception.

 

--- Which transaction attributes guarantee that the method is invoked within a transaction?

x

Required

 

Never

x

RequiresNew

x

Mandatory

 

NotSupported

 

Supported

 

--- An EJB Container provides which of the following services? Choose 4.

x

Transaction management

 

Polling

x

State management

x

Resource pooling

 

Adapter connections

x

Security checks

posted on 2007-07-09 16:36 Sun River 阅读(467) 评论(0)  编辑  收藏 所属分类: Java EE Questions